*division-specific variables
egen nCyes = sum((vote==1)*(party2s=="C")),by(divid)
egen nCno = sum((vote==0)*(party2s=="C")),by(divid)
egen nLyes = sum((vote==1)*(party2s=="L")),by(divid)
egen nLno = sum((vote==0)*(party2s=="L")),by(divid)
label var nCyes "n of yes votes cast by C party in this division"
label var nLyes "n of yes votes cast by L party in this division"

gen Cvote=((nCyes>nCno))
gen Lvote=((nLyes>nLno))

*egen Ayes = sum((vote==1)),by(divid)
*egen Noes = sum((vote==0)),by(divid)

*gen partyvote = ((nCyes>nCno&nLyes<nLno)|(nCyes<nCno&nLyes>nLno))
*label var partyvote "= ((nCyes>nCno&nLyes<nLno)|(nCyes<nCno&nLyes>nLno))"


* minority rolls
sort parl_n divid mpid
gen minority_roll=0 if partyvote==1
replace minority_roll=1 if majparty=="L"&partyvote==1&Lvote==1&Ayes>Noes 
replace minority_roll=1 if majparty=="C"&partyvote==1&Cvote==1&Ayes>Noes 

egen nmajbills = sum(divid!=divid[_n-1]&((majparty=="L"&Lvote==1)|(majparty=="C"&Cvote==1))&passage==1),by(parl_n)
egen nbillsopp = sum(divid!=divid[_n-1]&((majparty=="L"&Lvote==1)|(majparty=="C"&Cvote==1))&passage==1&((majparty=="L"&Cvote==0)|(majparty=="C"&Lvote==0))),by(parl_n)
egen nminroll2 = sum(divid!=divid[_n-1]&minority_roll==1&passage==1),by(parl_n)
gen pctminroll2 = nminroll2/nmajbills
gen pctbillopp = nbillsopp/nmajbills
label var nmajbills "n of bill passage motions on which majority wants yes in this parl_n"
label var nbillsopp "n of majority's bill passage motions opposed"
label var nminroll2 "n of minority rolls on bill passage motions in this parl_n"

* Figure 2
gen gap = pctbillopp - pctminroll2

sc pctminroll2 parl_s if parl_n!=parl_n[_n-1],c(L) msym(S) || sc pctbillopp parl_s if parl_n!=parl_n[_n-1],c(L) msym(D) legend(order(2 "Minority opposition rate" - 1 "Minority roll rate" -  3 "Smoothed gap")) ytitle("Share of bill passage motions") xtitle("Year parliament elected") || lowess gap parl_s if parl_n!=parl_n[_n-1],bwidth(.4)

